package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;


import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tanhua.domain.db.BlackList;
import com.tanhua.dubbo.api.BlackListApi;
import com.tanhua.dubbo.mapper.BlackListMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class BlackListApiImpl extends ServiceImpl<BlackListMapper, BlackList> implements BlackListApi {

    @Autowired
    private BlackListMapper blackListMapper;


    @Override
    public void deleteBlackUser(long userId, Long blackUserId) {
        QueryWrapper<BlackList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        queryWrapper.eq("black_user_id", blackUserId);
        blackListMapper.delete(queryWrapper);
    }

    @Override
    public List<BlackList> findBlack(long userId) {
        return blackListMapper.selectList(null);
    }

    @Override
    public void addBlacklist(Long userId, String blackId) {
        BlackList blackList = new BlackList();
        BlackListMapper blackListMapper = this.getBaseMapper();
        blackList.setUserId(userId);
        blackList.setBlackUserId(Long.parseLong(blackId));
        BlackList byId = blackListMapper.findById(String.valueOf(userId), blackId);
        if (byId == null) {
            blackListMapper.insert(blackList);
        }


    }
}
